import * as Constants from '../../constants'

const initialState = {
    isLoading: false,
    error: null,
    user: null,
    count: 0,
}

export default (state = initialState, { type, payload }) => {
    switch(type) {
        case Constants.LOGIN_REQUEST:
            return {
                ...state,
                isLoading: true,
            }
        case Constants.LOGIN_SUCCESS:
            state.count++
            return {
                ...state,
                isLoading: false,
                user: payload
            }
        case Constants.LOGIN_ERROR:
            return {
                ...state,
                isLoading: false,
                error: payload
            }
        default:
            return state
    }
}
